<template>
	<view class="page">
		<!-- 使用自定义标签 -->
		<!-- <helloComp myValue="美国硅谷"></helloComp> -->
		<!-- <trailer-stars innerScore="9.1" showNum="1"></trailer-stars> -->
		<!-- 轮播图 -->		
		<swiper class="carousel" :indicator-dots="true" :autoplay="true" >
			<swiper-item v-for="carousel in carouselList">
				<view class="swiper-item">
					<image class="carousel-img" :src="carousel.image" mode=""></image>
				</view>			
			</swiper-item>
			<!-- <swiper-item>
				<image class="carousel-img" src="../../static/carousel/batmanvssuperman.png" mode=""></image>
			</swiper-item>
			<swiper-item>
				<image class="carousel-img" src="../../static/carousel/spiderman.png" mode=""></image>
			</swiper-item> -->
		</swiper>

		<!-- 热门超英 -->
		<view class="page-block super-hot">
			<view class="hot-title-wapper">
				<image class="hot-icon" src="../../static/icos/hot.png" mode=""></image>
				<view class="hot-title">
					热门超英
				</view>
			</view>
		</view>
		<scroll-view class="page-block hot" scroll-x="true">
			<view class="single-poster" v-for="superhero in hotSuperheroList">
				<view class="poster-wapper">
					<image class="poster" :src="superhero.cover" mode=""></image>
					<view class="movie-name">
						{{superhero.name}}
					</view>
					<trailer-stars :innerScore="superhero.score" showNum="1"></trailer-stars>
				</view>
			</view>
			<view class="single-poster">
				<view class="poster-wapper">
					<image class="poster" src="../../static/poster/civilwar.jpg" mode=""></image>
					<view class="movie-name">
						蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠
					</view>
					<trailer-stars innerScore="7.8" showNum="1"></trailer-stars>
				</view>
			</view>
			
			<view class="single-poster">
				<view class="poster-wapper">
					<image class="poster" src="../../static/poster/civilwar.jpg" mode=""></image>
					<view class="movie-name">
						蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠
					</view>
					<trailer-stars innerScore="7.8" showNum="1"></trailer-stars>
				</view>
			</view>
			<view class="single-poster">
				<view class="poster-wapper">
					<image class="poster" src="../../static/poster/civilwar.jpg" mode=""></image>
					<view class="movie-name">
						蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠蝙蝠侠
					</view>
					<trailer-stars innerScore="7.8" showNum="1"></trailer-stars>
				</view>
			</view>
		</scroll-view>
		
		<!-- 热门预告 -->
		<view class="page-block super-hot">
			<view class="hot-title-wapper">
				<image class="hot-icon" src="../../static/icos/interest.png" mode=""></image>
				<view class="hot-title">
					热门预告
				</view>
			</view>
		</view>
		<view class="page-block trailer-hot">
			<video 
				class="trailer-sigle-video"
				v-for="trailer in trailerList"
				:src="trailer.trailer" 
				:poster="trailer.poster"
				controls></video>
		</view>
		
		<!-- 猜你喜欢 -->
		<view class="page-block super-hot">
			<view class="hot-title-wapper">
				<image class="hot-icon" src="../../static/icos/guess-u-like.png" mode=""></image>
				<view class="hot-title">
					猜你喜欢
				</view>
			</view>
		</view>
		<view class="page-block guess-u-like">
			<view class="single-like-movie" v-for="(guess,gIndex) in guessUList">
				<image class="poster" :src="guess.cover" mode=""></image>
				<view class="movie-desc">
					<view class="movie-title">
						{{guess.name}}
					</view>
					<trailer-stars :innerScore="guess.score"  showNum="1"></trailer-stars>
					<view class="movie-info">
						{{guess.basicInfo}}
					</view>
					<view class="movie-info">
						{{guess.releaseDate}}
					</view>
				</view>
				<view class="movie-operater" :data-gIndex="gIndex" @click="praiseMe">
					<image class="praise-ico" src="../../static/icos/praise.png" mode=""></image>
					<view class="praise-me">
						点赞
					</view>
					<view :animation="animationDataAttr[gIndex]" class="praise-me animation-opacity">
						+1
					</view>
				</view>
			</view>
			
			<!-- <view class="single-like-movie">
				<image class="poster" src="../../static/poster/justice.png" mode=""></image>
				<view class="movie-desc">
					<view class="movie-title">
						标题标题标题标题标题标题标题标题标题标题
					</view>
					<trailer-stars></trailer-stars>
					<view class="movie-info">
						2018 / 美国 / 科幻
					</view>
					<view class="movie-info">
						克里斯蒂安·贝尔饰 / 克里斯蒂安·贝尔饰
					</view>
				</view>
				<view class="movie-operater" @click="praiseMe">
					<image class="praise-ico" src="../../static/icos/praise.png" mode=""></image>
					<view class="praise-me">
						点赞
					</view>
					<view :animation="animationData" class="praise-me animation-opacity">
						+1
					</view>
				</view>
			</view>
			<view class="single-like-movie">
				<image class="poster" src="../../static/poster/justice.png" mode=""></image>
				<view class="movie-desc">
					<view class="movie-title">
						标题标题标题标题标题标题标题标题标题标题
					</view>
					<trailer-stars></trailer-stars>
					<view class="movie-info">
						2018 / 美国 / 科幻
					</view>
					<view class="movie-info">
						克里斯蒂安·贝尔饰 / 克里斯蒂安·贝尔饰
					</view>
				</view>
				<view class="movie-operater" @click="praiseMe">
					<image class="praise-ico" src="../../static/icos/praise.png" mode=""></image>
					<view class="praise-me">
						点赞
					</view>
					<view :animation="animationData" class="praise-me animation-opacity">
						+1
					</view>
				</view>
			</view>
			 -->
		</view>
	</view>
</template>

<script>
	// 导入自定义组件
	import helloComp from '../../components/helloComp.vue'
	import trailerStars from '../../components/trailerStars.vue'
	// import common from '../../common/common.js';
	// var severUrl = common.serverUrl;

	export default {
		data() {
			return {
				carouselList: [],
				hotSuperheroList: [],
				trailerList:[],
				guessUList:[],
				animationData:{},
				animationDataAttr:[],
				title: 'Hello'
			}
		},
		onPullDownRefresh() {
			this.refreshUlike();
		},
		onUnload() {
			this.animationData={};
			this.animationDataAttr=[]
		},
		onLoad() {
			var me = this;
			console.log(me.$serverUrl)
			var serverUrl=me.$serverUrl;
			
			this.animation=uni.createAnimation({
				
			})
			
			//请求轮播图数据
			uni.request({
				// url: 'https://www.imovietrailer.com/superhero/index/carousel/list',
				url: serverUrl+'/carousel.json',
				method: 'GET',
				data: {},
				success: res => {
					// debugger
					// console.log(res.data)
					if (res.data.status == 200) {
						var carouselList = res.data.data;
						me.carouselList = carouselList;
					}

				},
				fail: () => {},
				complete: () => {}
			});

			//查询热门超英
			uni.request({
				// url: 'https://www.imovietrailer.com/superhero/index/carousel/list',
				url: serverUrl+'/movie-hot.json',
				method: 'GET',
				data: {},
				success: res => {
					// debugger
					// console.log(res.data)
					if (res.data.status == 200) {
						
						var hotSuperheroList = res.data.data;
						me.hotSuperheroList = hotSuperheroList;
					}

				},
				fail: () => {},
				complete: () => {}
			});
			
			//查询热门预告
			uni.request({
				// url: 'https://www.imovietrailer.com/superhero/index/carousel/list',
				url: serverUrl+'/movie-hot.json',
				method: 'GET',
				data: {},
				success: res => {
					// debugger
					// console.log(res.data)
					if (res.data.status == 200) {
						
						var trailerList = res.data.data;
						me.trailerList = trailerList;
					}
			
				},
				fail: () => {},
				complete: () => {}
			});
			
			this.refreshUlike();

		},
		methods: {
			refreshUlike(){
				var me=this;
				var serverUrl=this.$serverUrl;
				
				uni.showLoading({
					mask:true
				});
				uni.showNavigationBarLoading()
				
				//查询猜你喜欢
				uni.request({
					// url: 'https://www.imovietrailer.com/superhero/index/carousel/list',
					url: serverUrl+'/movie-hot.json',
					method: 'GET',
					data: {},
					success: res => {
						// debugger
						// console.log(res.data)
						if (res.data.status == 200) {
							
							var guessUList = res.data.data;
							me.guessUList = guessUList;
						}
				
					},
					fail: () => {},
					complete: () => {
						uni.hideLoading();
						uni.hideNavigationBarLoading()
						uni.stopPullDownRefresh()
					}
				});
			},
			praiseMe(e){
				// debugger
				var gIndex=e.currentTarget.dataset.gindex;
				
				this.animation.translateY(-60).opacity(1).step({duration:400});
				this.animationData=this.animation;
				this.animationDataAttr[gIndex]=this.animationData.export()
				
				setTimeout(function(){
					this.animation.translateY(0).opacity(0).step({duration:0});
					this.animationData=this.animation;
					this.animationDataAttr[gIndex]=this.animationData.export()
				}.bind(this),500);
			}
		},
		components:{
			helloComp,
			trailerStars
		}
	}
</script>

<style lang="scss">
	.carousel {
		width: 750rpx;
		height: 440rpx;
	}

	.carousel-img {
		width: 750rpx;
		height: 440rpx;
	}

	.super-hot {
		margin-top: 12rpx;
		padding: 20rpx;
	}

	.hot-title-wapper {
		display: flex;
		flex-direction: row;
	}

	.hot-icon {
		width: 30rpx;
		height: 30rpx;
		margin-top: 15rpx;
	}

	.hot-title {
		font-size: 20px;
		margin-left: 20rpx;
		font-weight: bold;
	}

	.hot {
		width: 100%;
		white-space: nowrap;
	}

	.single-poster {
		display: inline-block;
		margin-left: 20rpx;
	}

	.poster-wapper {
		display: flex;
		flex-direction: column;
	}

	.poster {
		width: 200rpx;
		height: 270rpx;
	}

	.movie-name {
		width: 200rpx;
		margin-top: 10rpx;
		font-size: 14px;
		font-weight: bold;

		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	/* .movie-score-wapper {
		display: flex;
		flex-direction: row;
	}

	.star-icon {
		width: 20rpx;
		height: 20rpx;
		margin-top: 10rpx;
	}

	.movie-score {
		font-size: 15px;
		color: grey;
		margin-left: 10rpx;
	} */
	
	.trailer-hot{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0rpx 20rpx 20rpx 20rpx;
	}
	.trailer-hot .trailer-sigle-video{
		width: 350rpx;
		height: 220rpx;
		margin-top: 10rpx;
	}
	
	.guess-u-like{
		padding: 0 20rpx 20rpx 20rpx;
		display: flex;
		flex-direction: column;
		
		.single-like-movie{
			
			margin-top: 20rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			
			.poster{
				width: 180rpx;
				height: 240rpx;
				border: 3%;
			}
			
			.movie-desc{
				width: 340rpx;
				display: flex;
				flex-direction: column;
				.movie-title{
					font-size: 18px;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.movie-info{
					color: #808080;
					font-size: 12px;
					margin-top: 5rpx;
				}
			}
			.movie-operater{
				width: 140rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				border-left: dashed 2px;
				border-left-color: #dbdbdb;
				.praise-ico{
					width: 40rpx;
					height: 40rpx;
					
				}
				.praise-me{
					font-size: 14px;
					color: #feab2a;
				}
				.animation-opacity{
					font-weight: bold;
					opacity: 0;
				}
			}
		}
		
	}
</style>
